package cn.tedu.kit;

import java.sql.*;
import java.util.Arrays;

/**
 *  提取jdbc重复代码，提高复用性
 *  @author :Colin
 *  @version 创建时间: 2021/7/5 11:30
 *  @param rs结果集
 * @param
 * @param
 *
 */
public class JDBCUtils {
    final static public void close(ResultSet rs, Statement st, Connection conn){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }

        if(st!=null){
            try {
                st.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }

    }

    public static Connection getConnection() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");

        String url="jdbc:mysql://localhost:3306/colinbase?characterEncoding=utf8";
        Connection conn = DriverManager.getConnection(url, "root", "root");

        return conn;
    }

}
